package com.webex.ta.hydra.gui.action;

import com.webex.ta.hydra.gui.table.HydraTable;
import com.webex.ta.hydra.gui.GuiPackage;
import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.Constants;

import java.util.Set;
import java.util.HashSet;
import java.awt.event.ActionEvent;

/**
 * Author: Vegaz
 * Date: 2010-10-28
 * Time: 11:37:48
 */
public class DeleteValuesAction implements ActionHandler {
    private static Set<String> commands = new HashSet<String>();

    static {
        commands.add(ActionNames.REMOVE_VALUES);
    }

    public Set<String> getActionNames() {
        return commands;
    }

    public void doAction(ActionEvent e) {
        HydraTable table = GuiPackage.getInstance().getHydraTable();
        if (table.getSelectedRow() < 0) return;
        for (int row : table.getSelectedRows()) {
            Command cmd = table.getModel().getCommandAt(row);
            Command newCommand = cmd.clone();
            for (int col : table.getSelectedColumns()) {
                switch (col) {
                    case Constants.COLUMN_BREAKPOINT:
                        break;
                    case Constants.COLUMN_KEYWORD:
                        newCommand.setKeyword("");
                        break;
                    default:
                        newCommand.setParameter(col - 2, "");
                }
            }
            table.getModel().updateCommand(cmd, newCommand);
        }

        table.repaint();
    }
}
